/*
 * Copyright 2011 Niklas Kyster Rasmussen
 * 
 * This file is part of WotXP.
 *
 * WotXP is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * WotXP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WotXP; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

package net.nikr.wot.cmd;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Cmd {
	
	public static int getNumberInput(String output){
		return getNumberInput(output, false);
	}
	
	public static int getNumberInput(String output, boolean skipable){
		String s = getInput(output);
		try {
			return Integer.valueOf(s);
		} catch (NumberFormatException ex) {
			if (!skipable || !s.isEmpty()){
				System.out.println("Input must be a number - try again...");
				return getNumberInput(output, skipable);
			}
		}
		return 0;
	}
	
	public static String getInput(String output){
		System.out.print(output);
		try {
			BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
			return bufferRead.readLine();
		} catch(IOException e) {
			return "";
		}
	}
}
